//
//  BsTenantsViewModel.m
//  SameWorld(merchant)
//
//  Created by 李小朋 on 2017/4/18.
//  Copyright © 2017年 杨旭. All rights reserved.
//

#import "BsTenantsViewModel.h"

@implementation BsTenantsViewModel
+ (void)loadSendVerificationCodeNetWorking:(NSString *)phone andReturnValue:(returnValueBlock)returnValue andReturenError:(returenErrorBlock)returenError {
    
    //    118.190.98.64/tctxAPI/set_code.aspx&phone=15751033393
    NSString *urlStr = [NSString stringWithFormat:@"%@/set_code.aspx", serverUrl];
    NSDictionary *paramDic = @{@"phone":phone};
    [NetworkManager requestPOSTWithURLStr:urlStr paramDic:paramDic finish:^(id responseObject) {
        NSLog(@"获取验证码：%@",responseObject);
        NSDictionary *dataDic = [responseObject objectForKey:@"data"];
        NSString *code = [dataDic objectForKey:@"code"];
        returnValue(code);
        
    } enError:^(NSError *error) {
        returenError(error);
    }];
    
}

+ (void)loadSubmitFormNetWorking:(NSString *)name andPhone:(NSString *)phone andCode:(NSString *)code andShopname:(NSString *)shopname andDz:(NSString *)dz andReturenValue:(returnValueBlock)returnValue andReturenError:(returenErrorBlock)returenError {
    
    //    118.190.98.64/tctxAPI/submit_form.aspx?name=刘谣&phone=18652281519&code=222222&shopname=刘哥的锅子&dz=徐州市鼓楼区黄河路22号2单元222
    NSString *urlStr = [NSString stringWithFormat:@"%@/submit_form.aspx",serverUrl];
    
    if ([name isEqualToString:@""]) {
        [self showAlertWithTitle:@"姓名不能为空！"];
        return;
    }
    
    if ([phone isEqualToString:@""]) {
        [self showAlertWithTitle:@"手机号码不能为空！"];
        return;
    }
    
    if ([code isEqualToString:@""]) {
        [self showAlertWithTitle:@"请输入验证码！"];
        return;
    }
    
    if ([shopname isEqualToString:@""]) {
        [self showAlertWithTitle:@"门店名称不能为空！"];
        return;
    }
    
    if ([dz isEqualToString:@""]) {
        [self showAlertWithTitle:@"请输入您的地址！"];
        return;
    }

    NSDictionary *paramDic = @{@"name":name,@"phone":phone,@"code":code,@"shopname":shopname,@"dz":dz};
    
    NSLog(@"-- %@",paramDic);
    
    [NetworkManager requestPOSTWithURLStr:urlStr paramDic:paramDic finish:^(id responseObject) {
        NSLog(@"提交表单成功%@",responseObject);
        NSDictionary *dict = [NSDictionary dictionaryWithDictionary:responseObject];
        if ([[dict objectForKey:@"state"] integerValue] == 1) {
            NSString *message = [dict objectForKey:@"message"];
             returnValue(message);
        }else if ([[dict objectForKey:@"state"] integerValue] == 0) {
            NSLog(@"提交表单失败！");
            NSString *message = [dict objectForKey:@"message"];
            returnValue(message);
        }
        
    } enError:^(NSError *error) {
        returenError(error);

    }];
    
    
}




+ (void)showAlertWithTitle:(NSString *)title {
    
    CustomAlertActionView *alertView = [[CustomAlertActionView alloc] initWithViewType:(AlertTypeNotButton)];
    alertView.title = title;
    [alertView show];
    
}



@end
